package server

import (
	"fmt"
	pprof2 "github.com/gin-contrib/pprof"
	"github.com/gin-gonic/gin"
	"github.com/starmotioncf/common/cfgstruct"
	"github.com/starmotioncf/common/server/pprof"
)

func NewPProfServer(
	conf pprof.Config,
) *pprof.Server {
	switch cfgstruct.DefaultsType() {
	case cfgstruct.DefaultsRelease:
		gin.SetMode(gin.ReleaseMode)
	case cfgstruct.DefaultsTest:
		gin.SetMode(gin.TestMode)
	default:
		gin.SetMode(gin.DebugMode)
	}
	s := pprof.NewServer(gin.Default(), conf)
	fmt.Println(conf)
	if conf.Switch {
		pprof2.Register(s, conf.Prefix)
	}
	return s
}
